package org.jshand.jxc.business.component;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.ScrollPaneLayout;
import javax.swing.table.DefaultTableModel;

public class JTablePanel extends JScrollPane {

	public JTablePanel() {
		this(getTable2());
		//this.setPreferredSize(new Dimension(500, 300));
		this.setBackground(Color.MAGENTA);
		JToolBar tool = new JToolBar();
		tool.add(new JButton("按钮"));
	}

	public JTablePanel(Component view) {
		super(view);
	}
	
	
	public static JTable getTable(){
		JTable table = new JTable(30,20);
		
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < i+1; j++) {
				table.getModel().setValueAt(j+"*"+i+"="+(j*i), i, j);
			}
		}
		
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		table.setBorder(BorderFactory.createTitledBorder("JTable table = new JTable(30,20);"));
		
		return table;
	}
	
	public static JTable getTable2(){
		String[][] data = new String[9][9];
		Object[] columnNames =  new Object[9];
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < i+1; j++) {
				data[i-1][j-1] = j+"*"+i+"="+(j*i);
			}
			columnNames[i-1] = "第"+i+"-列";
		}
		JTable table = new JTable(data,columnNames);
//		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		table.setBorder(BorderFactory.createTitledBorder("JTable table = new JTable(data,columnNames);"));
		return table;
	}
	
	public static JTable getTable3(){
		String[][] data = new String[9][9];
		Object[] columnNames =  new Object[9];
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j < i+1; j++) {
				data[i-1][j-1] = j+"*"+i+"="+(j*i);
			}
			columnNames[i-1] = "第"+i+"-列";
		}
		JTable table = new JTable(new DefaultTableModel(data, columnNames));
		table.setBorder(BorderFactory.createTitledBorder("DefaultTableModel"));
//		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		
		return table;
	}
	
	
	
	


}
